package com.m2bshop.shop.controller;

import com.m2bshop.shop.dao.dataDictionary;
import com.m2bshop.shop.pageHelper.paging;
import com.m2bshop.shop.pojo.data_dictionary;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class dataDicationaryController {

    @Autowired
    private dataDictionary dataDictionary;

    @Autowired
    private paging paging;

    @RequestMapping("/countDataDictionary")
    public int count(){
        return dataDictionary.count();
    }

    @RequestMapping("/findalldataDictionary/{pagenum}/{pagesize}")   //查询数据字典
    public List<data_dictionary> findall(@PathVariable int pagenum, @PathVariable int pagesize){

        paging.pagehelper(pagenum, pagesize);

        return dataDictionary.findall();
    }

    @RequestMapping("/findbyiddataDictionary/{id}")
    public data_dictionary findbyid(@PathVariable int id){
        return dataDictionary.findbyid(id);
    }

    @RequestMapping("/inertonedataDictionary") //新增数据字典
    public int insertone(String dictionaryType, String descrioptionOfUse, String code, String codeValue){
        data_dictionary data_dictionary = new data_dictionary();
        data_dictionary.setDictionaryType(dictionaryType);
        data_dictionary.setDescrioptionOfUse(descrioptionOfUse);
        data_dictionary.setCode(code);
        data_dictionary.setCodeValue(codeValue);
        return dataDictionary.insertone(data_dictionary);
    }

    @RequestMapping("/updateonedataDictionary")   //根据ID修改数据字典
    public int updateone(data_dictionary data_dictionary){
        return dataDictionary.updateone(data_dictionary);
    }

    @RequestMapping("/deleteonedataDictionary/{id}")    //根据ID删除数据字典
    public int deleteone(@PathVariable int id){
        return dataDictionary.deleteone(id);
    }

}
